package com.fyzk.utils;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;

import com.fyzk.activity.app.App;

/**
 * 获取屏幕长宽的工具类
 *
 */
public class ScreenUtils {
	
	private static ScreenUtils intance;
	
	private  int width;
	private  int height;
	private  float density;
	private  int densityDPI; 
	
	private ScreenUtils(){
		WindowManager wm = (WindowManager)App.getContext().getSystemService(Context.WINDOW_SERVICE);
		DisplayMetrics dm = new DisplayMetrics();
		wm.getDefaultDisplay().getMetrics(dm);
		
		setHeight(dm.heightPixels);
		setWidth(dm.widthPixels);
		setDensity(dm.density);
		setDensityDPI(dm.densityDpi);
	}
	
	public static ScreenUtils getInstance(){
		if(intance == null){
			intance = new ScreenUtils();
		}
		return intance;
	}
	/**
	 * 得到屏幕的宽度
	 * @return width 屏幕的宽度
	 */
	public int getWidth() {
		return width;
	}

	private void setWidth(int width) {
		this.width = width;
	}

	/**
	 * 得到屏幕的高度
	 * @return height 屏幕的高度
	 */
	public int getHeight() {
		return height;
	}

	private void setHeight(int height) {
		this.height = height;
	}
	/**
	 * 得到屏幕的密度
	 * @return density 屏幕的密度
	 */
	public float getDensity() {
		return density;
	}

	private void setDensity(float density) {
		this.density = density;
	}
	/**
	 * 得到屏幕的densityDpi
	 * @return densityDpi
	 */
	public int getDensityDPI() {
		return densityDPI;
	}

	private void setDensityDPI(int densityDPI) {
		this.densityDPI = densityDPI;
	}
	
	public int getStatusBarHeight() {
		int statusBarHeight1 = -1;
		//获取status_bar_height资源的ID
		int resourceId = App.getContext().getResources().getIdentifier("status_bar_height", "dimen", "android");
		if (resourceId > 0) {
			//根据资源ID获取响应的尺寸值
			statusBarHeight1 = App.getContext().getResources().getDimensionPixelSize(resourceId);
		}
		return statusBarHeight1;
	}
	

}
